package com.weaver.drools.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.weaver.drools.common.utils.LLog;

import java.util.Map;
/**
 * 
*  @application name： json转换工具
*  @author: zhouxinlei
*  @time：2018年7月18日
*  @version：ver 1.1
 */
public class Json2Util {
    private static final ObjectMapper om = new ObjectMapper();

    public static String toJsonString(Object bean) {
        try {
            return om.writeValueAsString(bean);
        } catch (JsonProcessingException arg1) {
            LLog.error(arg1);
            return null;
        }
    }

    public static <T> T toBean(String jsonString, Class<T> beanClass) {
        try {
            return om.readValue(jsonString, beanClass);
        } catch (Exception arg2) {
            LLog.error(arg2);
            return null;
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public static Map<String, Object> toMap(String jsonString) {
        try {
            return (Map) om.readValue(jsonString, Map.class);
        } catch (Exception arg1) {
            LLog.error(arg1);
            return null;
        }
    }
}
